home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / May MacUser Program.cpt / miniGenApp Src / MiscUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  3.3 KB  |  141 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             MiscUtil.c
  3.     
  4.     DESCRIPTION:     Useful utilities for memory allocation and other duties
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc., All Rights Reserved.
  9.     
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     3.30.90    -    May 1990 MacUser Release
  14.     ==========================================================
  15.  
  16.    ***************************************************************************** */
  17. #include "Version.h"
  18.  
  19. #ifdef V4
  20. #include <stdio.h>
  21. #endif
  22.  
  23. #ifdef V3
  24. #include <Proto.h>
  25. #endif
  26.  
  27. #ifdef V2
  28. #include <asm.h>
  29. #include <MemoryMgr.h>
  30. #include <Pascal.h>
  31. #include <Proto.h>
  32. #endif
  33.  
  34. #include "AppGlobals.h"
  35.  
  36. #include "DialogUtilPr.h"
  37. #include "WindowUtilPr.h"
  38.  
  39. #include "MiscUtilPr.h"
  40.  
  41. /*---------------------------------------------------------------------------
  42.     newClearPtr -     allocate a zeroed, non-relocatable memory object of size 
  43.     3.30.90kwgm        bytes and return its pointer
  44. ----------------------------------------------------------------------------*/
  45. Ptr
  46. newClearPtr (size)
  47.     Size            size;
  48. {
  49.     Ptr                thePtr;
  50.     Size            freeMem;
  51.     OSErr            err;
  52.     char            s [64];
  53.     
  54.     if (size < 0L)
  55.     {
  56.         if (gDevel)
  57.             pDebugStr ("\pnewClearPtr: negative size");
  58.             
  59.         return (0L);
  60.     }
  61.  
  62.     freeMem = MaxBlock ();
  63.  
  64.     thePtr = 0L;
  65.     if (size < freeMem)
  66.     {
  67.         /* use "glue" to allocate the zeroed memory */
  68.         asm
  69.         {
  70.             move.l        size, d0
  71.             NewPtr      CLEAR
  72.             move.l        a0, thePtr
  73.         }
  74.  
  75.         if (err = MemError())    /* test for success */
  76.         {
  77.             if (gDevel)
  78.             {
  79.                 sprintf (s,"newClearPtr: mem error %d", err);
  80.                 CtoPstr (s);
  81.                 pDebugStr (s);
  82.             }
  83.     
  84.             thePtr = 0L;    /* clear out the ptr on memory error */
  85.         }
  86.     }
  87.     
  88.     return (thePtr);
  89.         
  90. } /* newClearPtr */
  91.  
  92. /* ------------------------------------------------------------------------------------
  93.     pDebugStr  -    provide sensible interface for error messages and allow a user the
  94.     3.30.90kwgm        choice of actions
  95. --------------------------------------------------------------------------------------- */
  96. Boolean
  97. pDebugStr  (string)
  98.     StringPtr            string;
  99. {
  100.     unsigned short        flags;
  101.     short                theItem, type;
  102.     Rect                box;
  103.     DialogPtr             theDialog;
  104.     GrafPtr                savePort;
  105.     ControlHandle        itemHdl;
  106.     
  107.     SysBeep (1);            /* beep the bell */
  108.     GetPort (&savePort);    /* save graphic environment */
  109.  
  110.     /* get the dialog for the message */
  111.     if (!(theDialog = GetNewDialog (kDebugMsgDLOG, 0L, -1L)))
  112.         return (false);
  113.     
  114.     /* hilite the default button */
  115.     GetDItem (theDialog, kDebugMsgOKOutline, &type, &itemHdl, &box);
  116.     SetDItem (theDialog, kDebugMsgOKOutline, type, buttonProc, &box);
  117.  
  118.     ParamText (0L, string, 0L, 0L);        /* set up to write the error string */
  119.  
  120.     centerWindow (theDialog);
  121.     ShowHide (theDialog, true);
  122.     
  123.     /* display the dialog, wait for button */
  124.     ModalDialog (DLOGfilterProc1, &theItem);
  125.     
  126.     DisposDialog (theDialog);        /* restore environment */
  127.     SetPort (savePort);
  128.  
  129.     /* switch on user choice */
  130.     if (theItem == kDebugMsgExit)
  131.         ExitToShell();
  132.     else if (theItem == kDebugMsgCancel)
  133.         return (false);
  134.     else
  135.         return (true);
  136.     
  137. } /* pDebugStr */
  138.  
  139. /* ===========================================  EOF  ========================================
  140.     Copyright © 1990 by Code of the West, Inc., All Rights Reserved.
  141. ============================================================================================ */